home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / tvmode / tvmode.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  7KB  |  236 lines

  1. #include <stdio.h>
  2. /* dostv - (C) Copyright ムンパッパ (MHB02550)     
  3.  *                         Ver. 1.0 1990/5/27
  4.  *                         Ver. 1.1 1990/5/31
  5.  *                         Ver. 1.2 1991/1/ 2
  6.  * tvmode - (C) Copyright ムンパッパ (MHB02550)     
  7.  *                         Ver. 0.5 1991/1/ 6
  8.  *                         Ver. 1.0 1991/4/11
  9.  *
  10.  * このソフトウェアは自由にコピ-、改変、配布が出来ます。
  11.  */
  12. #include <dos.h>
  13. #include "tvmode.h"
  14.  
  15. int            bright;
  16. static int        off_flg = 0;
  17. static int        mode = 5; /* DOS TV ON */
  18. static int        priority = 5;
  19. static int        ctr = 0x15;
  20. static short        *table = on_tbl;
  21. static unsigned char        *palette = don_plt;
  22. static unsigned char        plt_buf[96];
  23.  
  24. main(argc, argv) 
  25.     int    argc;
  26.     char    *argv[];
  27. {
  28.  
  29.     register int    i;
  30.     static union REGS regs;
  31.     static struct SREGS sregs;
  32.  
  33.     readplt(plt_buf);
  34.     for (i = 0; i < MAXMODE; ++i) {
  35.     if (!pltcmp(plt_buf, now_plt[i])) {
  36.         mode = i;
  37.         table = new_tbl[mode];
  38.         palette = new_plt[mode];
  39.         priority = pritab[mode];
  40.         off_flg = (mode & 1)?0:1;
  41.         goto chkarg;
  42.     }
  43.     }
  44. chkarg:
  45.     getarg(argc, argv);
  46.  
  47.     outportb(0x440, 30);
  48.     if (!off_flg && !(inport(0x442) & 0x100)) { /* ビデオ入力なし */
  49.         table[28] &= 0xbfff;            /* 内部同期  */
  50.         table[28] |= 0x00c0;            /* ス-パ-インポ-ズ無効 */
  51.     }
  52.  
  53.     for (i = 0; i < MAXBLK; ++i) {
  54.         outportb(0x440, (unsigned char)i);
  55.     outport(0x442, table[i]);
  56.     }
  57.     setplt16(palette);
  58.     if (off_flg) {
  59.         outportb(0x448, (unsigned char)0);
  60.         outportb(0x44a, 0x15);
  61.         outportb(0x448, (unsigned char)1);
  62.         outportb(0x44a, priority);
  63.         outportb(0xfda0, 0xf);
  64.     outportb(0x440, (unsigned char)28);
  65.     outport(0x442, 0x803f);         /* ビデオ スタ-ト */
  66.         /* 電子ボリュ-ム */
  67.         outportb(0x04e1, 0x0);        /* LINE 左 OFF     */
  68.         outportb(0x04e1, 0x1);        /* LINE 右 OFF     */
  69.         outportb(0x04e0, 0x0);        /* ボリュ-ム MIN  */
  70.     }
  71.     else {
  72.         outportb(0x448, (unsigned char)0);
  73.         outportb(0x44a, ctr);
  74.         outportb(0x448, (unsigned char)1);
  75.         outportb(0x44a, priority);
  76.         outportb(0xfda0, 0xf);
  77.     outportb(0x440, (unsigned char)28);
  78.     outport(0x442, table[28] | 0x8000);         /* ビデオ スタ-ト */
  79.  
  80.         /* 電子ボリュ-ム */
  81.  
  82.         outportb(0x04e1, 0x04);        /* LINE 左 ON      */
  83.         outportb(0x04e1, 0x05);        /* LINE 右 ON      */
  84.         outportb(0x04e0, 0x3f);        /* ボリュ-ム MAX  */
  85.     }
  86. }
  87. getarg(argc, argv) 
  88.     int    argc;
  89.     char    **argv;
  90. {
  91.     register int    i, argcnt;
  92.     for (argcnt = 1; argc >= 2; --argc, ++argcnt) {
  93.     if ((!strcmp(argv[argcnt],"off"))||(!strcmp(argv[argcnt],"OFF"))) {
  94.         off_flg = 1;
  95.         mode &= 0xfffe;
  96.         table = new_tbl[mode];
  97.         palette = new_plt[mode];
  98.         priority = pritab[mode];
  99.     }
  100.     else if ((!strcmp(argv[argcnt],"on"))||(!strcmp(argv[argcnt],"ON"))) {
  101.         off_flg = 0;
  102.         mode |= 1;
  103.         table = new_tbl[mode];
  104.         palette = new_plt[mode];
  105.         priority = pritab[mode];
  106.     }
  107.     else if ((!strcmp(argv[argcnt],"ful"))||(!strcmp(argv[argcnt],"FUL"))) {
  108.             table[30] = 3;                          /* フルト-ン */
  109.     }
  110.     else if ((!strcmp(argv[argcnt],"high"))||(!strcmp(argv[argcnt],"HIGH"))) {
  111.             priority &= 0xfb;                        /* 高輝度 */
  112.     }
  113.     else if ((!strcmp(argv[argcnt],"cmp"))||(!strcmp(argv[argcnt],"CMP"))) {
  114.             priority |= 0x8;                         /* ス-パ-インポ-ズOFF */
  115.             table[28] &= 0xbf;                      /* 内部同期 */
  116.     }
  117.     else if ((!strcmp(argv[argcnt],"video"))||(!strcmp(argv[argcnt],"VIDEO"))) {
  118.             ctr = 0x10;                              /* DISPLAY OFF */
  119.     }
  120.     else if ((!strncmp(argv[argcnt],"ap=",3))||(!strncmp(argv[argcnt],"AP=",3))) {
  121.             apset(palette, &(argv[argcnt][3]));          /* analog palette set */
  122.     }
  123.     else {
  124.         for (i = 0; i < MAXMODE; ++i) {
  125.         if ((!strcmp(argv[argcnt],mode1[i]))||
  126.             (!strcmp(argv[argcnt],mode2[i]))) {
  127.             mode = i;
  128.             off_flg = (mode & 1)?0:1;
  129.             table = new_tbl[mode];
  130.             palette = new_plt[mode];
  131.             priority = pritab[mode];
  132.             goto next_arg;
  133.         }
  134.         }
  135.         fprintf(stderr,"USAGE: %s [mode] [options...]\n", argv[0]);
  136.         fprintf(stderr,"mode\n");
  137.         fprintf(stderr,"    dos   : MS-DOS モ-ド\n");
  138.         fprintf(stderr,"    plt   : MOPTERM オ-トパイロットモ-ド\n");
  139.         fprintf(stderr,"    rtc   : MOPTERM チャットモ-ド\n");
  140.         fprintf(stderr,"    ori   : ORICON モ-ド\n");
  141.         fprintf(stderr,"    dmy   : DMYCON モ-ド\n");
  142.         fprintf(stderr,"option\n");
  143.         fprintf(stderr,"    off   : TVを切る\n");
  144.         fprintf(stderr,"    on    : TVをつける\n");
  145.         fprintf(stderr,"    ful   : フルト-ン(デフォルトはハ-フト-ン)\n");
  146.         fprintf(stderr,"    high  : 高輝度(デフォルトは低輝度)\n");
  147.         fprintf(stderr,"    cmp   : コンピュ-タ出力のみ(デフォルトはス-パ-インポ-ズ)\n");
  148.         fprintf(stderr,"    video : ビデオ出力のみ(デフォルトはス-パ-インポ-ズ)\n");
  149.         fprintf(stderr,"    ap=ファイル名 : ファイル名のアナログパレットを使う\n");
  150.         exit(1);
  151. next_arg:
  152.     }
  153.     }
  154. }
  155. setplt16(plt16)
  156.     unsigned char    *plt16;
  157. {
  158.     register int    i;
  159.         outportb(0x448, (unsigned char)1);
  160.         outportb(0x44a, 1);          /* 16色パレットレイア0 */
  161.     for (i = 0; i < 16; ++i) {
  162.         outportb(0xfd90, i);
  163.         outportb(0xfd92, *plt16++);
  164.         outportb(0xfd94, *plt16++);
  165.         outportb(0xfd96, *plt16++);
  166.     }
  167.  
  168.         outportb(0x448, (unsigned char)1);
  169.         outportb(0x44a, 0x21);          /* 16色パレットレイア1 */
  170.  
  171.     for (i = 0; i < 16; ++i) {
  172.         outportb(0xfd90, i);
  173.         outportb(0xfd92, *plt16++);
  174.         outportb(0xfd94, *plt16++);
  175.         outportb(0xfd96, *plt16++);
  176.     }
  177. }
  178. readplt(pltbuf)
  179.     unsigned char *pltbuf;
  180. {
  181.     register int    i;
  182.  
  183.         outportb(0x448, (unsigned char)1);
  184.         outportb(0x44a, 5);         /* 16色パレットレイア0 */
  185.  
  186.     for (i = 0; i < 16; ++i) {
  187.         outportb(0xfd90, i);
  188.         *pltbuf++ = inportb(0xfd92) & 0xf0;
  189.         *pltbuf++ = inportb(0xfd94) & 0xf0;
  190.         *pltbuf++ = inportb(0xfd96) & 0xf0;
  191.     }
  192.  
  193.         outportb(0x448, (unsigned char)1);
  194.         outportb(0x44a, 0x25);          /* 16色パレットレイア1 */
  195.  
  196.     for (i = 0; i < 16; ++i) {
  197.         outportb(0xfd90, i);
  198.         *pltbuf++ = inportb(0xfd92);
  199.         *pltbuf++ = inportb(0xfd94);
  200.         *pltbuf++ = inportb(0xfd96);
  201.     }
  202. }
  203. pltcmp(plt_buf, now_plt)
  204.     unsigned char    *plt_buf;
  205.     unsigned char    *now_plt;
  206. {
  207.     register int    i;
  208.     for (i = 0; i < 96; ++i) {
  209.     if (plt_buf[i] != now_plt[i]) {
  210.             return(1);
  211.     }
  212.     }
  213.     return(0);
  214. }
  215. apset(palette, fname)
  216.     unsigned char    *palette;
  217.     char        *fname;
  218. {
  219.     FILE        *ifp;
  220.     register int    i;
  221.     static int        tmp1,tmp2,tmp3;
  222.     static char        dust[BUFSIZ];
  223.     
  224.     if ((ifp = fopen(fname,"r"))==NULL) {
  225.         fprintf(stderr,"Can't open \"%s\"\n",fname);
  226.         exit(1);
  227.     }
  228.     for (i = 0; i < 32; ++i) {
  229.         fscanf(ifp, "%d%d%d%[^\n]\n", &tmp1, &tmp2, &tmp3, dust);
  230.     palette[i*3+0] = tmp1;
  231.     palette[i*3+1] = tmp2;
  232.     palette[i*3+2] = tmp3;
  233.      /* printf("%4d%4d%4d\n", palette[i*3+0], palette[i*3+1], palette[i*3+2]);*/
  234.     }
  235. }
  236.